package tech.aistar.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.dto.AgentGrade;
import tech.aistar.entity.House;
import tech.aistar.service.IAgentService;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/agent")
public class AgentGradeController {

    @Autowired
    private IAgentService agentService;


    @RequestMapping("/select")
    public String selectAgent(HttpServletRequest request){
        String sea = request.getParameter("sea");
//        List<AgentGrade> agentGradeList = agentService.selectAgent();


        String pageNow = request.getParameter("pageNow");
        pageNow = pageNow==null?"1":pageNow;

        //sea = sea==null?null:sea;
        //System.out.println(pageNow);
        PageInfo<AgentGrade> pageInfo = agentService.findByPage(null,Integer.valueOf(pageNow), 4);
        //PageInfo<AgentGrade> pageInfo2 = agentService.findByPage(sea,Integer.valueOf(pageNow), 4);

        request.setAttribute("page",pageInfo);
        //request.setAttribute("page2",pageInfo2);

        return "/home_page/jingjirenliebiao";
    }


    @RequestMapping("/bind")
    public String bindAgent(HttpServletRequest request){

        Integer id = null;

        if(request.getParameter("agent_id")!=""){
            id = Integer.valueOf(request.getParameter("agent_id"));
        }
        //System.out.println("=======");
        //System.out.println("id2+"+id);
        request.setAttribute("agent_id",id);
        return "/home_page/middle";
    }


//    @RequestMapping("/search")
//    public String searchAgent(HttpServletRequest request){
//        String name = request.getParameter("sea");
//
//        List<AgentGrade> agentGradeList1 = agentService.selectAgentByName(name);
//
//        //request.setAttribute("agent",agentGradeList1);
//
//        return "/home_page/jingjirenliebiao";
//    }


}
